﻿using System;
using System.Diagnostics;

namespace ExtendedMvc.Common.Diagnostics {
	public static class Check {
		public static class Argument {
			[DebuggerStepThrough]
			public static void IsNotNull(object parameter, string parameterName) {
				if (parameter == null)
					throw new ArgumentNullException(parameterName, Messages.ArgumentCannotBeNull.FormatWith(parameterName));
			}

			[DebuggerStepThrough]
			public static void IsNotNullOrEmpty(string parameter, string parameterName) {
				if (string.IsNullOrEmpty(parameter))
					throw new ArgumentException(Messages.ArgumentCannotBeNullOrEmpty.FormatWith(parameterName), parameterName);
			}

			[DebuggerStepThrough]
			public static void IsNotNullOrWhiteSpace(string parameter, string parameterName) {
				if (string.IsNullOrWhiteSpace(parameter))
					throw new ArgumentException(Messages.ArgumentCannotBeNullOrEmpty.FormatWith(parameterName), parameterName);
			}

			[DebuggerStepThrough]
			public static void IsNotZeroOrNegative(int parameter, string parameterName) {
				if (parameter <= 0)
					throw new ArgumentOutOfRangeException(parameterName, Messages.ArgumentCannotBeNegativeOrZero.FormatWith(parameterName));
			}

			[DebuggerStepThrough]
			public static void IsNotNegative(int parameter, string parameterName) {
				if (parameter < 0)
					throw new ArgumentOutOfRangeException(parameterName, Messages.ArgumentCannotBeNegative.FormatWith(parameterName));
			}

			[DebuggerStepThrough]
			public static void IsNotZeroOrNegative(long parameter, string parameterName) {
				if (parameter <= 0)
					throw new ArgumentOutOfRangeException(parameterName, Messages.ArgumentCannotBeNegativeOrZero.FormatWith(parameterName));
			}

			[DebuggerStepThrough]
			public static void IsNotNegative(long parameter, string parameterName) {
				if (parameter < 0)
					throw new ArgumentOutOfRangeException(parameterName, Messages.ArgumentCannotBeNegative.FormatWith(parameterName));
			}

			[DebuggerStepThrough]
			public static void IsNotValid(object parameter, string parameterName, Predicate<object> validation, string message = null) {
				Check.Argument.IsNotNull(validation, "validation");
				if (!validation(parameter))
					throw new ArgumentOutOfRangeException(parameterName, message ?? Messages.ArgumentInvalid.FormatWith(parameterName));
			}
		}
	}
}
